﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <script src="/js/header.js"></script>
</head>
<body style="background-color: white;">
    <section class="container-fluid" style="background-color: white;">
        <form class="form-horizontal m15_t" id="form">
            <div class="tab-content">
                <div class="tab-pane fade in active" id="home">
                    <div class="form-group">
                        <label class="wd100 control-label"><span class="WdateFmtErr">*</span>公司名称：</label>
                        <div class="wd250 m15_l">
                            <select class="form-control" name="companyId">
                                <option value="">请选择</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="wd100 control-label"><span class="WdateFmtErr">*</span>客户单号：</label>
                        <div class="wd250 m15_l">
                            <input class="form-control" type="text" name="withdrawalOrderNo" maxlength="40" autocomplete="off" placeholder="长度必须介于 3 和 40 之间">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="wd100 control-label"><span class="WdateFmtErr">*</span>付款金额：</label>
                        <div class="wd250 m15_l">
                            <input class="form-control" type="text" name="withdrawalAmount" maxlength="10" autocomplete="off" placeholder="请正确填写付款金额">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="wd100 control-label"><span class="WdateFmtErr">*</span>客户银行：</label>
                        <div class="wd250 m15_l">
                            <div class="wd250">
                                <select class="form-control" name="bankCode">
                                    <option value="">请选择</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="wd100 control-label"><span class="WdateFmtErr">*</span>客户姓名：</label>
                        <div class="wd250 m15_l">
                            <input class="form-control" type="text" name="withdrawalAccountName" maxlength="40" autocomplete="off" placeholder="长度必须介于 3 和 40 之间">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="wd100 control-label"><span class="WdateFmtErr">*</span>客户卡号：</label>
                        <div class="wd250 m15_l">
                            <input class="form-control" type="text" name="withdrawalCardNumber" maxlength="20" autocomplete="off" placeholder="长度必须介于 15 和 20 之间">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="wd100 control-label">客户银行地区：</label>
                        <div class="wd250 m15_l">
                            <input class="form-control" type="text" name="withdrawalBankAddress" maxlength="40" autocomplete="off" placeholder="请正确填写客户银行地区,">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="wd100 control-label">备注：</label>
                        <div class="wd250 m15_l">
                            <textarea class="form-control" type="text" name="paymentRemark" maxlength="40" autocomplete="off" placeholder="备注"></textarea>
                        </div>
                    </div>
                </div>
            </div>
        </form>

    </section>

    <script type="text/javascript">

        var validator = null;

        var companyId = $("select[name='companyId']");
        var bankCode = $("select[name='bankCode']");

        $(function () {

            var cover = FlashPay.UI.Mask({
                obj: $("body"),
                opacity: 0.5
            });

            FlashPay.Util.Ajax({
                type: "POST",
                url: "/Payment/GetPaymentRecord/",
                data: null,
                success: function (response) {
                    if (response.success) {

                        if (response.data.companyResponse != null) {
                            companyId.empty();
                            companyId.append("<option value=''>请选择</option>");

                            $.each(response.data.companyResponse, function (i, item) {
                                companyId.append("<option value='" + item.companyID + "'>" + item.companyName + "</option >");
                            });
                        }

                        if (response.data.bankInfoResponse != null) {
                            bankCode.empty();
                            bankCode.append("<option value=''>请选择</option>");

                            $.each(response.data.bankInfoResponse, function (i, item) {
                                bankCode.append("<option value='" + item.bankCode + "'>" + item.bankName + "</option >");
                            });
                        }
                        cover.Remove();
                    } else {

                    }
                },
                error: function (e) {
                    FlashPay.UI.Tip_short_warning("操作失败！请查看网络，请重试");
                }
            });

            validator = FlashPay.Util.Validator({
                formObj: $("#form"),
                rules: {
                    companyId: {
                        required: true
                    },
                    withdrawalOrderNo: {
                        required: true,
                        rangelength: [3, 40]
                    },
                    bankCode: {
                        required: true,
                    },
                    withdrawalAmount: {
                        required: true,
                        money: true
                    },
                    withdrawalAccountName: {
                        required: true,
                        specialChar: true,
                        rangelength: [2, 40]
                    },
                    withdrawalCardNumber: {
                        required: true,
                        rangelength: [15, 20]
                    }
                },
                messages: {
                    companyId: {
                        required: "请选择付款公司"
                    },
                    withdrawalOrderNo: {
                        required: "长度必须介于 3 和 40 之间",
                        rangelength: "长度必须介于 3 和 40 之间"
                    },
                    bankCode: {
                        required: "请选择客户银行"
                    },
                    withdrawalAmount: {
                        required: "请输入付款金额",
                        money: "付款金额格式有误,最多保留两位小数"
                    },
                    withdrawalAccountName: {
                        required: "长度必须介于 2 和 40 之间",
                        rangelength: "长度必须介于 2 和 40 之间"
                    },
                    withdrawalCardNumber: {
                        required: "长度必须介于 15 和 20 之间数字",
                        rangelength: "长度必须介于 15 和 20 之间数字",
                    }
                },
            });

        })

        function save() {

            if (!validator.form()) {
                return false;
            }

            var paymentCard = {};
            paymentCard.companyId = $("select[name='companyId']").find("option:selected").val();
            paymentCard.withdrawalOrderNo = $("input[name='withdrawalOrderNo']").val();
            paymentCard.withdrawalAmount = $("input[name='withdrawalAmount']").val();
            paymentCard.withdrawalCardBankFlag = $("select[name='bankCode']").find("option:selected").val();
            paymentCard.withdrawalBankName = $("select[name='bankCode']").find("option:selected").text();
            paymentCard.withdrawalAccountName = $("input[name='withdrawalAccountName']").val();
            paymentCard.withdrawalCardNumber = $("input[name='withdrawalCardNumber']").val();
            paymentCard.withdrawalBankAddress = $("input[name='withdrawalBankAddress']").val();
            paymentCard.paymentRemark = $("input[name='paymentRemark']").val();

            FlashPay.Util.Ajax({
                url: '/Payment/PaymentRecordAdd',
                type: 'POST',
                data: paymentCard,
                success: function (response) {
                    if (response.success) {
                        FlashPay.UI.DialogOpener().Tip_success("操作成功！");
                        FlashPay.UI.DialogOpener().doSearch();
                        FlashPay.UI.CloseDialog();
                    } else {
                        FlashPay.UI.Tip_short_warning("操作失败！" + response.errorMessage);
                    }
                },
                error: function (json) {
                    FlashPay.UI.Tip_short_warning("操作失败！请查看网络，请重试!");
                }
            });
        }
    </script>
</body>
</html>